package com.guan.eduservice.controller;


import com.guan.commonutils.R;
import com.guan.eduservice.entity.subjet.OneSubject;
import com.guan.eduservice.service.EduSubjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2022-12-31
 */
@RestController
@RequestMapping("/eduservice/subject/*")
@CrossOrigin
public class EduSubjectController {

    @Autowired
    private EduSubjectService subjectService;

    /** 添加课程分类
     *  获取上传文件，读取内容
     *  @Param MultipartFile file 上传的文件
     */
    @PostMapping("addSubject")
    public R addSubject(MultipartFile file){
        //得到上传的文件
        subjectService.saveSubject(file,subjectService);
        return R.ok();
    }


    /** 查询所有的课程
     * 树形结构
     * 创建符和结构数据的vo实体类  一级分类vo 二级分类vo
     */
    @GetMapping("getAllSubject")
    public R getAllSubject(){
        List<OneSubject> allSubject = subjectService.getAllSubject();
        return R.ok().data("list",allSubject);
    }



}

